<?php

namespace App\Http\Controllers;

use App\Ones;
use Illuminate\Http\Request;

class One extends Controller
{
    public function add(){
        return view('insert');
    }
    public function stuAdd(Request $request){
        $validatedData = $request->validate([
            'name' => 'required',
            'age' => 'required',
            'score' => 'required',
            'rank' => 'required',
        ]);
        $data=[
          'name'=>$request['name'],
          'age'=>$request['age'],
          'score'=>$request['score'],
          'rank'=>$request['rank'],
        ];
        $res=Ones::stuAdd($data);
        if($res){
            echo "添加成功";
        }else{
            echo "添加失败";
        }
    }
    public function stuShow(){
        $data=Ones::getAll();
        return view('show',['data'=>$data]);
    }
    public function del(Request $request){
        $id=$request['id'];
        $res=Ones::del($id);
        if($res){
            echo "删除成功";
        }else{
            echo "删除失败";
        }
    }
}
